limsPreFolder.historyChoosePage = {

    getGridParam : function() {
        var _this = this, columns = limsPreFolder.getHisTaskChooseListColumns();
        _this.param.single ? columns.unshift({
            radio : true
        }) : columns.unshift({
            checkbox : true
        });
        return {
            type : 'grid',
            id : 'lims-pre-folder-choose-list-grid',
            url : limsPreFolder.baseUrl + '/history/sample/queries',
            requestData : _this.param,
            page : true,
            columns : columns,
            autoSave : false,
            filterOpen: true,
            // onLoadSuccess : function(data) {
            //     if (!Gikam.isEmpty(data)) {
            //         this.activeRowByIndex(0);
            //     }
            // },
            // onRowActive : function(index, row) {
            //     Gikam.getAsyncComp('lims-folder-derivative-sample-list-grid').done(function(grid) {
            //         grid.refresh({
            //             url : limsPreFolder.derivativelUrl + '/queries',
            //             requestData: {
            //                 folderId_EQ: row.ext$.folderid
            //             }
            //         });
            //     });
            //
            // },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.CONFIRM',
                icon : 'select',
                onClick : function() {
                    Gikam.getLastModal().close(Gikam.getComp('lims-pre-folder-choose-list-grid').getSelections());
                }
            }, {
                type: 'button',
                text: 'T_LIMS_SAMPLE.SAMPLECODE',
                icon: 'select',
                onClick: function () {
                    var mainGrid = Gikam.getComp('lims-pre-folder-choose-list-grid')
                    Gikam.createLimsModal({
                        title: 'T_CORE_CHART.SEARCHRULE',
                        height: '300',
                        width: '400',
                        onConfirm: function () {
                            var form = Gikam.getComp('sampleCode-form-prefolder');
                            var data = form.getData()
                            if (Gikam.isEmpty(data)) {
                                return;
                            }
                            var requestData = _this.param;
                            requestData.sampleCode_IN = data.sampleCode.replace(/[(\r\n)|(\ +)|(，)|(；)|(;)]/g, ',');
                            Gikam.postText(limsPreFolder.baseUrl + '/history/sample/queries', Gikam.getJsonWrapper({
                                f: requestData,
                                n : -1
                            })).done(function (data) {
                                data = JSON.parse(data)
                                mainGrid.loadData(data.rows)
                            }).always(function () {
                                Gikam.getLastModal().close()
                            });
                        },
                        m : {
                            type: 'form',
                            id: 'sampleCode-form-prefolder',
                            columns: 1,
                            titleWidth: 120,
                            fields: [{
                                field: 'sampleCode',
                                title: 'T_LIMS_SAMPLE.SAMPLECODE',
                                type: 'textarea',
                                colspan: 2,
                                height: 180,
                            }],
                        }
                    })
                }
            }]
        }
    },

    getSampleGrid: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-folder-derivative-sample-list-grid',
            page: true,
            columns: limsPreFolder.getAllDerivativeEditListColumns(),
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.USE',
                icon : 'select',
                onClick : function() {
                    let comp = Gikam.getComp('lims-pre-folder-choose-list-grid');
                    var activedRow = comp.getActivedRow();
                    var sample = Gikam.getComp('lims-folder-derivative-sample-list-grid').getActivedRow()
                    if (Gikam.isEmpty(sample)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM')
                        return
                    }
                    console.log(activedRow);
                    comp.setData({
                        index: activedRow.gridIndex,
                        sampleId: sample.derivativeId,
                        sampleCode: sample.derivativeNo,
                        sampleTypeCode: sample.ext$.sampletypecode,
                        sampleTypeName: sample.ext$.sampletype,
                    })
                }
            } ]
        }
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-pre-folder-choose-list-layout',
            renderTo : Gikam.getLastModal().window.$dom,
            // west : {
            //     width : '60%',
            //     items : [_this.getGridParam()]
            // },
            // center : {
            //     title: 'MODULE.BUSINESS.RESULT.TAB.DERIVATIVE',
            //     items : [ this.getSampleGrid() ]
            // }
            center : {
                items : [ this.getGridParam() ]
            }
        });
    },

    init : function(param) {
        this.param = param;
        this.create();
    }
};
